const { Product, Category } = require('../models');

async function checkProducts() {
  try {
    console.log('正在查询数据库中的商品数据...');
    
    const products = await Product.findAll({
      include: [{
        model: Category,
        as: 'category',
        attributes: ['id', 'name']
      }]
    });
    
    console.log(`数据库中共有 ${products.length} 个商品：`);
    
    if (products.length === 0) {
      console.log('数据库中没有商品数据。');
    } else {
      products.forEach((product, index) => {
        console.log(`[${index + 1}] ID: ${product.id}, 名称: ${product.name}, 分类ID: ${product.category_id}, 价格: ${product.price}`);
      });
    }
    
    console.log('\n检查完成!');
  } catch (error) {
    console.error('查询商品数据时出错:', error);
  } finally {
    process.exit(0);
  }
}

checkProducts(); 